package designpattern.singleton.type7;

/*
    单例模式的静态内部类
    优点：
        线程安全
        懒加载（当外部类加载时内部类不会主动加载，只有当getInstance()方法执行时才会加载一次）
 */
public class Singleton {
    private Singleton(){}

    private static class SingleInstance{
        public static final Singleton SINGLETON = new Singleton();
    }

    public static Singleton getInstance(){
        return SingleInstance.SINGLETON;
    }
}
class Test{
    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new Thread(()->{
                System.out.println(Singleton.getInstance());
            }).start();
        }
    }
}
